<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.value"
          clearable
          placeholder="输入搜索内容"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="700px"
      >
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="100px">

          <el-form-item label="库区名称" prop="reservoirAreaName">
            <el-input v-model="form.reservoirAreaName" />
          </el-form-item>
          <el-form-item label="库房数量">
            <el-input v-model="form.warehouseNumber" />
          </el-form-item>
          <el-form-item label="库房序号">
            <el-input v-model="form.warehouseSerialNumber" />
          </el-form-item>
          <el-form-item label="库房名称">
            <el-input v-model="form.warehouseName" />
          </el-form-item>
          <el-form-item label="库房形式">
            <el-input v-model="form.warehouseModus" />
          </el-form-item>
          <el-form-item label="库房结构">
            <el-input v-model="form.warehouseStructure" />
          </el-form-item>
          <el-form-item label="储存类型">
            <el-input v-model="form.storageType" />
          </el-form-item>
          <el-form-item label="储存量">
            <el-input v-model="form.storageNumber" />
          </el-form-item>
          <el-form-item label="审核周期">
            <el-input v-model="form.auditCycle" />
          </el-form-item>
          <el-form-item label="火灾等级">
            <el-input v-model="form.fireLevel" />
          </el-form-item>
          <el-form-item label="上次审核时间">
            <el-date-picker v-model="form.lastAuditTime" type="datetime" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="reservoirAreaName" label="库区名称" />
        <el-table-column prop="warehouseNumber" label="库房数量" />
        <el-table-column prop="warehouseSerialNumber" label="库房序号" />
        <el-table-column prop="warehouseName" label="库房名称" />
        <el-table-column prop="warehouseModus" label="库房形式" />
        <el-table-column prop="warehouseStructure" label="库房结构" />
        <el-table-column prop="storageType" label="储存类型" />
        <el-table-column prop="storageNumber" label="储存量" />
        <el-table-column prop="auditCycle" label="审核周期" />
        <el-table-column prop="fireLevel" label="火灾等级" />
        <!--<el-table-column prop="lastAuditTime" label="上次审核时间">-->
        <!--<template slot-scope="scope">-->
        <!--<span>{{ parseTime(scope.row.lastAuditTime) }}</span>-->
        <!--</template>-->
        <!--</el-table-column>-->
        <el-table-column
          v-permission="['admin','reservoirAreaManage:edit','reservoirAreaManage:del']"
          label="操作"
          width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />

            <button @click="routerTo(scope.row.id)">详情</button>

          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudReservoirAreaManage from '@/api/mhm/reservoirAreaManage'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  id: null,
  createTime: null,
  updateTime: null,
  createBy: null,
  updateBy: null,
  reservoirAreaName: null,
  warehouseNumber: null,
  warehouseSerialNumber: null,
  warehouseName: null,
  warehouseModus: null,
  warehouseStructure: null,
  storageType: null,
  storageNumber: null,
  auditCycle: null,
  fireLevel: null,
  lastAuditTime: null
}
export default {
  name: 'ReservoirAreaManage',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '库区管理',
      url: 'api/reservoirAreaManage',
      sort: 'id,desc',
      crudMethod: { ...crudReservoirAreaManage }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'reservoirAreaManage:add'],
        edit: ['admin', 'reservoirAreaManage:edit'],
        del: ['admin', 'reservoirAreaManage:del']
      },
      rules: {
        reservoirAreaName: {
          required: true, message: '请输入库区名称', trigger: 'blur'
        }
      },
      queryTypeOptions: [
        { key: 'reservoirAreaName', display_name: '库区名称' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    },
    routerTo(id) {
      this.$router.push({ path: '/reservoirAreaManage', query: { reservoirAreaManageId: id }})
    }
  }
}
</script>

<style scoped>

</style>
